<template>
  <div>
    <HmPage
      pageTitle="面经登录"
      pageButton="提交"
      type="warning"
      @login="handleLogin"
    >
    </HmPage>
    <van-nav-bar right-text="注册账号" @click-right="$router.push('/register')">
    </van-nav-bar>
    <router-view></router-view>
  </div>
</template>

<script>
import axios from "axios"
import HmPage from "@/components/HmPage.vue"

export default {
  components: {
    HmPage,
  },
  methods: {
    async handleLogin(user, pass) {
      try {
        const res = await axios({
          url: "http://interview-api-t.itheima.net/h5/user/login",
          method: "post",
          data: {
            username: user,
            password: pass,
          },
        })
        console.log("登录成功:", res.data)
        localStorage.setItem("token", res.data.data.token)
        console.log(res.data.data.token)
        this.$router.push("/layout/interview/recommend")
      } catch (error) {
        console.error("登录失败:", error)

        alert("登录失败，请重试")
      }
    },
  },
}
</script>

<style></style>
